<script setup lang="ts">
import { ref, reactive } from "vue";
import { useSettingStore } from "@/stores";
import { storeToRefs } from "pinia";

const settingStore = useSettingStore();
const { indexConfig } = storeToRefs(settingStore);

// 城市人口数据
const populationData = reactive({
  resident: 2408.23, // 常住人口(万人)
  nonResident: 1219.22, // 外来人口(万人)
  ratio: 50.6, // 居住比例(%)
  ageGroups: [
    { age: '0-18', female: 42, male: 58 },
    { age: '19-30', female: 44, male: 56 },
    { age: '30-55', female: 54, male: 46 },
    { age: '55+', female: 55, male: 45 }
  ]
});
</script>

<template>
  <div class="population-card">
    <div class="population-main">
      <div class="population-nums">
        <div class="population-item">
          <div class="label">常住人口</div>
          <div class="value resident">{{ populationData.resident }}</div>
        </div>
        <div class="population-item">
          <div class="label">外来人口</div>
          <div class="value non-resident">{{ populationData.nonResident }}</div>
        </div>
        <div class="population-item">
          <div class="label">居住比</div>
          <div class="value ratio">{{ populationData.ratio }}%</div>
        </div>
      </div>
      
      <div class="age-distribution">
        <div class="distribution-header">
          <span class="age-label">年龄</span>
          <span class="female-label">女</span>
          <span class="male-label">男</span>
        </div>
        
        <div class="distribution-item" v-for="(item, index) in populationData.ageGroups" :key="index">
          <span class="age">{{ item.age }}</span>
          <div class="bar-container">
            <div class="female-bar" :style="{ width: item.female + '%' }">{{ item.female }}%</div>
            <div class="male-bar" :style="{ width: item.male + '%' }">{{ item.male }}%</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.population-card {
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  color: #fff;
  display: flex;
  flex-direction: column;
  

  
  .population-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    
    .population-nums {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      
      .population-item {
        text-align: center;
        flex: 1;
        
        .label {
          font-size: 14px;
          opacity: 0.8;
          margin-bottom: 5px;
        }
        
        .value {
          font-size: 24px;
          font-weight: bold;
          
          &.resident {
            color: #24f8ff;
          }
          
          &.non-resident {
            color: #1219ff;
          }
          
          &.ratio {
            color: #ffdd11;
          }
        }
      }
    }
    
    .age-distribution {
      flex: 1;
      margin-top: 20px;
      
      .distribution-header {
        display: flex;
        margin-bottom: 10px;
        font-size: 14px;
        opacity: 0.8;
        
        .age-label {
          width: 50px;
        }
        
        .female-label {
          flex: 1;
          text-align: center;
        }
        
        .male-label {
          flex: 1;
          text-align: center;
        }
      }
      
      .distribution-item {
        display: flex;
        align-items: center;
        margin-bottom: 15px;
        
        .age {
          width: 50px;
          font-size: 14px;
        }
        
        .bar-container {
          flex: 1;
          display: flex;
          height: 30px;
          position: relative;
          
          .female-bar {
            background: linear-gradient(to right, #ff56e2, #f012ff);
            display: flex;
            align-items: center;
            justify-content: flex-end;
            padding-right: 5px;
            font-size: 12px;
            height: 100%;
            border-radius: 4px 0 0 4px;
          }
          
          .male-bar {
            background: linear-gradient(to right, #2c8fff, #00eeff);
            display: flex;
            align-items: center;
            padding-left: 5px;
            font-size: 12px;
            height: 100%;
            border-radius: 0 4px 4px 0;
          }
        }
      }
    }
  }
}
</style>
